]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
search: Replace getResultMeta() with getResultMetas()
authorFlorian Müllner <fmuellner@gnome.org>
Fri, 17 Feb 2012 15:39:27 +0000 (16:39 +0100)
committerFlorian Müllner <fmuellner@gnome.org>
Tue, 21 Feb 2012 22:00:53 +0000 (23:00 +0100)
Save some function calls by fetching all search results we want to
display for a provider at once, rather than one result at a time.

https://bugzilla.gnome.org/show_bug.cgi?id=663125

js/ui/appDisplay.js
js/ui/contactDisplay.js
js/ui/docDisplay.js
js/ui/placeDisplay.js
js/ui/search.js
js/ui/searchDisplay.js
js/ui/wanda.js

index 5d845e635ef46ae979b3cdcce7ee56515648e777..28c820c8fb40e84bcb3d7148666afd6a38237fa0 100644 (file)
@@ -312,13 +312,18 @@ const AppSearchProvider = new Lang.Class({
         this._appSys = Shell.AppSystem.get_default();
     },
 
-    getResultMeta: function(app) {
-        return { 'id': app,
-                 'name': app.get_name(),
-                 'createIcon': function(size) {
-                                   return app.create_icon_texture(size);
-                               }
-               };
+    getResultMetas: function(apps) {
+        let metas = [];
+        for (let i = 0; i < apps.length; i++) {
+            let app = apps[i];
+            metas.push({ 'id': app,
+                         'name': app.get_name(),
+                         'createIcon': function(size) {
+                             return app.create_icon_texture(size);
+                         }
+                       });
+        }
+        return metas;
     },
 
     getInitialResultSet: function(terms) {
@@ -369,13 +374,18 @@ const SettingsSearchProvider = new Lang.Class({
         this._gnomecc = this._appSys.lookup_app('gnome-control-center.desktop');
     },
 
-    getResultMeta: function(pref) {
-        return { 'id': pref,
-                 'name': pref.get_name(),
-                 'createIcon': function(size) {
-                                   return pref.create_icon_texture(size);
-                               }
-               };
+    getResultMetas: function(prefs) {
+        let metas = [];
+        for (let i = 0; i < prefs.length; i++) {
+            let pref = prefs[i];
+            metas.push({ 'id': pref,
+                         'name': pref.get_name(),
+                         'createIcon': function(size) {
+                             return pref.create_icon_texture(size);
+                         }
+                       });
+        }
+        return metas;
     },
 
     getInitialResultSet: function(terms) {
index ed213d411793f361b17a74ea7ddc2d482d80af2b..e501d801c7c1101db8f180be8cb06a40cbba4e49 100644 (file)
@@ -149,14 +149,18 @@ const ContactSearchProvider = new Lang.Class({
         this._contactSys = Shell.ContactSystem.get_default();
     },
 
-    getResultMeta: function(id) {
-        let contact = new Contact(id);
-        return { 'id': id,
-                 'name': contact.alias,
-                 'createIcon': function(size) {
-                         return contact.createIcon(size);
-                 }
-        };
+    getResultMetas: function(ids) {
+        let metas = [];
+        for (let i = 0; i < ids.length; i++) {
+            let contact = new Contact(ids[i]);
+            metas.push({ 'id': ids[i],
+                         'name': contact.alias,
+                         'createIcon': function(size) {
+                             return contact.createIcon(size);
+                         }
+                       });
+        }
+        return metas;
     },
 
     getInitialResultSet: function(terms) {
index b331d03657779d89d57e5560c73b4a81caa5fd91..dc840dafe2c8f2df83d25a2a4f40194cca74a8ae 100644 (file)
@@ -14,16 +14,21 @@ const DocSearchProvider = new Lang.Class({
         this._docManager = DocInfo.getDocManager();
     },
 
-    getResultMeta: function(resultId) {
-        let docInfo = this._docManager.lookupByUri(resultId);
-        if (!docInfo)
-            return null;
-        return { 'id': resultId,
-                 'name': docInfo.name,
-                 'createIcon': function(size) {
-                                   return docInfo.createIcon(size);
-                               }
-               };
+    getResultMetas: function(resultIds) {
+        let metas = [];
+        for (let i = 0; i < resultIds.length; i++) {
+            let docInfo = this._docManager.lookupByUri(resultIds[i]);
+            if (!docInfo)
+                metas.push(null);
+            else
+                metas.push({ 'id': resultIds[i],
+                             'name': docInfo.name,
+                             'createIcon': function(size) {
+                                 return docInfo.createIcon(size);
+                             }
+                           });
+        }
+        return metas;
     },
 
     activateResult: function(id, params) {
index 334cdab976908b224c58030f54515590c2e498f4..9c1352c403f8c914026564c22a3c0e29e91a372c 100644 (file)
@@ -367,16 +367,21 @@ const PlaceSearchProvider = new Lang.Class({
         this.parent(_("PLACES & DEVICES"));
     },
 
-    getResultMeta: function(resultId) {
-        let placeInfo = Main.placesManager.lookupPlaceById(resultId);
-        if (!placeInfo)
-            return null;
-        return { 'id': resultId,
-                 'name': placeInfo.name,
-                 'createIcon': function(size) {
-                                   return placeInfo.iconFactory(size);
-                               }
-               };
+    getResultMetas: function(resultIds) {
+        let metas = [];
+        for (let i = 0; i < resultIds.length; i++) {
+            let placeInfo = Main.placesManager.lookupPlaceById(resultIds[i]);
+            if (!placeInfo)
+                metas.push(null);
+            else
+                metas.push({ 'id': resultIds[i],
+                             'name': placeInfo.name,
+                             'createIcon': function(size) {
+                                 return placeInfo.iconFactory(size);
+                             }
+                           });
+        }
+        return metas;
     },
 
     activateResult: function(id, params) {
index 52cd7a86a2dad8f7f0cb23f3adb531a901c6fab8..86173c67e5948cff7dd057c40b10af6d9a2a468f 100644 (file)
@@ -190,14 +190,14 @@ const SearchProvider = new Lang.Class({
     },
 
     /**
-     * getResultMeta:
-     * @id: Result identifier string
+     * getResultMetas:
+     * @ids: Result identifier strings
      *
-     * Return an object with 'id', 'name', (both strings) and 'createIcon'
-     * (function(size) returning a Clutter.Texture) properties which describe
-     * the given search result.
+     * Return an array of objects with 'id', 'name', (both strings) and
+     * 'createIcon' (function(size) returning a Clutter.Texture) properties
+     * with the same number of members as @ids
      */
-    getResultMeta: function(id) {
+    getResultMetas: function(ids) {
         throw new Error('Not implemented');
     },
 
index 57478b76fe4ee6ef03bc461441a2cc545afe85c1..85a0631502a3252f3fb91cf7df90a98d9cdc1221 100644 (file)
@@ -126,10 +126,13 @@ const GridSearchResults = new Lang.Class({
         let canDisplay = this._grid.childrenInRow(this._width) * MAX_SEARCH_RESULTS_ROWS
                          - this._grid.visibleItemsCount();
 
-        for (let i = Math.min(this._notDisplayedResult.length, canDisplay); i > 0; i--) {
-            let result = this._notDisplayedResult.shift();
-            let meta = this.provider.getResultMeta(result);
-            let display = new SearchResult(this.provider, meta, this._terms);
+        let numResults = Math.min(this._notDisplayedResult.length, canDisplay);
+        if (numResults == 0)
+            return;
+        let results = this._notDisplayedResult.splice(0, numResults);
+        let metas = this.provider.getResultMetas(results);
+        for (let i = 0; i < metas.length; i++) {
+            let display = new SearchResult(this.provider, metas[i], this._terms);
             this._grid.addItem(display.actor);
         }
     },
index 9deb448fb18664611a99b2067d3f815cc536eefe..632b251acdfcdb1ecd3305b9b1cd944690f7ed09 100644 (file)
@@ -168,22 +168,23 @@ const WandaSearchProvider = new Lang.Class({
         this.parent(_("Your favorite Easter Egg"));
     },
 
-    getResultMeta: function(fish) {
-        return { 'id': fish,
-                 'name': capitalize(fish),
-                 'createIcon': function(iconSize) {
-                     // for DND only (maybe could be improved)
-                     // DON'T use St.Icon here, it crashes the shell
-                     // (dnd.js code assumes it can query the actor size
-                     // without parenting it, while StWidget accesses
-                     // StThemeNode in get_preferred_width/height, which
-                     // triggers an assertion failure)
-                     return St.TextureCache.get_default().load_icon_name(null,
-                                                                         'face-smile',
-                                                                         St.IconType.FULLCOLOR,
-                                                                         iconSize);
-                 }
-               };
+    getResultMetas: function(fish) {
+        return [{ 'id': fish[0], // there may be many fish in the sea, but
+                                 // only one which speaks the truth!
+                  'name': capitalize(fish[0]),
+                  'createIcon': function(iconSize) {
+                      // for DND only (maybe could be improved)
+                      // DON'T use St.Icon here, it crashes the shell
+                      // (dnd.js code assumes it can query the actor size
+                      // without parenting it, while StWidget accesses
+                      // StThemeNode in get_preferred_width/height, which
+                      // triggers an assertion failure)
+                      return St.TextureCache.get_default().load_icon_name(null,
+                                                                          'face-smile',
+                                                                          St.IconType.FULLCOLOR,
+                                                                          iconSize);
+                  }
+                }];
     },
 
     getInitialResultSet: function(terms) {